package PTA2.ti7;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author Lenovo
 */


public class Main {
    public static void main(String[] args) {
        ArrayList strList = new ArrayList();
        Scanner in = new Scanner(System.in);
        while (true) {
            String s = in.next();
            if (!s.equals("!!end!!")) {
                strList.add(s);
            } else
                break;
        }
        strList.add(0, "begin");
        strList.add("end");
        System.out.println(strList);
        String str = new String();
        str = in.next();
        System.out.println(strList.contains(str));
        System.out.println(strList.indexOf(str));
        System.out.println(strList.lastIndexOf(str));
        System.out.println(strList.get(0));
        strList.remove(0);
        System.out.println(strList);
        str = in.next();
        strList.set(1, str);
        System.out.println(strList);
        ArrayList strList1 = new ArrayList();
        str = in.next();
        in.close();
        for (int j = 0; j < strList.size(); j++) {
            if (((String) strList.get(j)).contains(str)) {
                strList1.add(strList.get(j));
            }
        }
        System.out.println(strList1);
        strList.remove(str);
        System.out.println(strList);
        strList.clear();
        System.out.println(strList + "," + strList.size() + "," + strList.isEmpty());
    }
}
